package com.admin.util;

import java.util.Date;
import java.util.List;

import com.admin.bean.ProvinceBean;
import com.admin.service.ProvinceService;
import com.admin.util.db.DbOperation;


public class BillingUtil {

	public static List getPageList(int pageNo,int pageSize,List list) {
		int index = (pageNo-1)*pageSize;
    	if(index>=list.size()) {
    		return list.subList(0, 0);
    	} else {
    		int maxRoomIndex = ((pageNo)*pageSize < list.size() ? (pageNo)*pageSize : list.size());
    		System.out.println(index);
    		System.out.println(maxRoomIndex);
        	return list.subList(index, maxRoomIndex);
    	}
	}
	
	
	//TODO 根据手机号码前六位取得省份
	public static int getProvinceId(String phoneNumber,String msg) {
		if(phoneNumber == null || phoneNumber.length()<7) {
			return 0;
		}
		String phoneSub = phoneNumber.substring(0,7);
		
		String provinceName = SqlUtil.getStringResult("select province from net_region_infos where phnId = "+phoneSub,DbOperation.DB_CONTENT);
		if(provinceName==null) {
			
			
				SqlUtil.executeUpdate("insert into project2_no_register values("+phoneNumber+",'',getDate())", DbOperation.DB_CONTENT);
				return 0;
			
			
		}
		ProvinceBean bean = ProvinceService.getProvince(provinceName);
		return bean!=null?bean.getId():0;
	}
	
	
	public static String getRecvDay(){
		Date date = new Date();
		return "recv_"+DateUtil.formatDate(date, "yyMMdd");
		
	}
	
	public static String getStatRecvDay(){
		Date date = new Date(new Date().getTime()-24*3600*1000l);
		return "recv_"+DateUtil.formatDate(date, "yyMMdd");
	}
	
	public static String getStatRecvHour(){
		Date date = new Date(new Date().getTime()-3600*1000l);
		return "recv_"+DateUtil.formatDate(date, "yyMMdd");
	}
	
	public static String getSendDay(){
		Date date = new Date();
		return "send_"+DateUtil.formatDate(date, "yyMMdd");
	}
	
	public static String getStatSendDay(){
		Date date = new Date(new Date().getTime()-24*3600*1000l);
		return "send_"+DateUtil.formatDate(date, "yyMMdd");
	}
	
	public static String getStatSendHour(){
		Date date = new Date(new Date().getTime()-3600*1000l);
		return "send_"+DateUtil.formatDate(date, "yyMMdd");
	}
	
	public static void main(String[] args) {
		System.out.println(getStatRecvDay());
	}
	
}
